﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace StateMachineViewerMobile.Runtime.Xml
{
    public class TransactionXml
    {
        [XmlElement("state_in")]
        public String StateIn { get; set; }

        [XmlElement("symbol")]
        public Char Symbol { get; set; }

        [XmlArray("states_out")]
        [XmlArrayItem("state")]
        public List<String> StatesOut { get; set; }

        public TransactionXml()
        {
            StatesOut = new List<string>();
        }

        public TransactionXml(String state, Char symbol)
        {
            StateIn = state;
            Symbol = symbol;
            StatesOut = new List<string>();
        }

        public TransactionXml(String state, Char symbol, List<String> result)
        {
            StateIn = state;
            Symbol = symbol;
            StatesOut = result;
        }

        /// <summary>
        /// Retorna uma string que representa a transição.
        /// </summary>
        /// <returns>Retorna uma string no formato [StateIn] --[Symbol]--> [StatesOut,StatesOut,...] </returns>
        public String GetTransactionDescription()
        {
            return String.Format("{0} --{1}--> {2}", this.StateIn, this.Symbol, String.Join(",", this.StatesOut.ToArray()));
        }
    }
}
